import store from "../store/index.js"
const baseUrl = "/api"


export const MyRequest = (obj) => {
	return new Promise((resolve, reject) => {
		console.log(obj.params)
		uni.request({
			header: {
				'custom-header': 'hello' //自定义请求头信息
			},
			sslVerify:false,
			url: baseUrl + obj.url,
			method: obj.method || 'GET',
			data: obj.data || obj.params || {},
			success: (res) => {
				if (res.data.code == 200) {
					return resolve(res)
				} else {
					uni.showToast({
						icon:"error",
						title: res.data.message,
					})
					// if(){
					// 	if(!store.state.user.id){
					// 		console.log('未登录')
					// 		uni.navigateTo({
					// 			url:"/pages/login/login"
					// 		})
					// 	}	
					// }
					console.log(res)
				}
			},
			fail: (err) => {
				uni.showToast({
					icon:"error",
					title: '请求失败'
				})
				console.log(err)
				return reject(err)
			}
		})
	})
}
